#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
LFforecast 服务器启动脚本
"""

import sys
import os
from pathlib import Path

# 添加项目根目录到Python路径
project_root = Path(__file__).parent.absolute()
sys.path.insert(0, str(project_root))

def main():
    try:
        # 导入配置
        from backend.config.settings import settings
        
        print("🚀 正在启动 LFforecast 电力负载预测系统...")
        print(f"📍 项目路径: {project_root}")
        print(f"🌐 服务地址: http://{settings.SERVER_HOST}:{settings.SERVER_PORT}")
        print(f"📚 API 文档: http://{settings.SERVER_HOST}:{settings.SERVER_PORT}/docs")
        print("-" * 60)
        
        # 导入并创建app
        from backend.main import app
        
        # 启动服务器
        import uvicorn
        uvicorn.run(
            app,
            host=settings.SERVER_HOST,
            port=settings.SERVER_PORT,
            reload=False,
            log_level="info"
        )
        
    except ImportError as e:
        print(f"❌ 导入错误: {e}")
        print("💡 请确保已激活正确的conda环境：conda activate lfforecast")
        sys.exit(1)
    except Exception as e:
        print(f"❌ 启动失败: {e}")
        sys.exit(1)

# 设置环境变量来消除CPU核心数检测警告
os.environ['LOKY_MAX_CPU_COUNT'] = '4'  # 设置为4个核心

if __name__ == "__main__":
    main() 